package com.jinxin.platform.cdqzsqacs.interceptor;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-06-30
 * @Author: Lingnan
 **/

import com.jinxin.platform.cdqzsqacs.rpc.SysUserRpc;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * URL拦截，做对应处理
 *
 */
@Component
@Slf4j
public class URLInterceptor implements HandlerInterceptor {
    @Autowired
    private SysUserRpc sysUserRpc;

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        String path = request.getServletPath();
        if(path.equals("/unAuth/api/downdata/getConfigs.html")){
            log.info("设备请求getConfigs接口完成，开始向设备发送更新设备参数命令");
            String controllersn = request.getParameter("controllersn");
            if(!StringUtils.isEmpty(controllersn)){
                sysUserRpc.updateDeviceParams(controllersn.toLowerCase());
            }
        }
    }
}
